package com.ruoyi.shop.emporium.profit.service.impl;

import com.ruoyi.mall.common.domain.ProfitLossStatement;
import com.ruoyi.mall.common.mapper.ProfitLossStatementMapper;
import com.ruoyi.shop.emporium.profit.service.IProfitLossStatementService;
import com.ruoyi.shop.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProfitLossStatementServiceImpl implements IProfitLossStatementService {

    @Autowired
    private ProfitLossStatementMapper profitLossStatementMapper;

    @Override
    public List<ProfitLossStatement> getProfitLossStatement(Date beginDate, Date endDate, String type) {

        // 确保结束日期包含一整天
        Date adjustedEndDate = DateUtils.addDays(endDate, 1);

        Map<String, Object> params = new HashMap<>();
        params.put("beginDate", beginDate);
        params.put("endDate", adjustedEndDate);

        if ("monthly".equals(type)) {
            return profitLossStatementMapper.selectMonthlyProfitLoss(params);
        } else {
            return profitLossStatementMapper.selectDailyProfitLoss(params);
        }
    }
}
